CREATE OR REPLACE FUNCTION prj_country_name(bigint) RETURNS varchar
AS '
DECLARE
       act_id ALIAS FOR $1;
       ct integer;
       ret varchar;

BEGIN
        ct:=lpd_get_prj_obj_count(23,act_id);
        IF ct = 0 THEN
                RETURN ''-'';
        END IF;

        IF ct = 1 THEN
                SELECT INTO ret cnt.name FROM countries_iso3 cnt,
                locations l2, objects o2 WHERE l2.id = o2.id
                AND cnt.iso3 = l2.country_iso3 AND o2.activity_id = act_id
                AND o2.obj_type=23;
                RETURN ret;
        END IF;

        RETURN ''--multiple--'';
END;
' LANGUAGE plpgsql;